package com.jihad.sbd.common.utils;

import org.apache.http.HttpStatus;

import java.util.HashMap;
import java.util.Map;

/**
 * 返回数据
 * 
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2016年10月27日 下午9:59:27
 */
public class ResponseUtil extends HashMap<String, Object> {
	private static final long serialVersionUID = 1L;
	
	public ResponseUtil() {
		put("code", 0);
	}
	
	public static ResponseUtil error() {
		return error(HttpStatus.SC_INTERNAL_SERVER_ERROR, "未知异常，请联系管理员");
	}
	
	public static ResponseUtil error(String msg) {
		return error(HttpStatus.SC_INTERNAL_SERVER_ERROR, msg);
	}
	
	public static ResponseUtil error(int code, String msg) {
		ResponseUtil r = new ResponseUtil();
		r.put("code", code);
		r.put("msg", msg);
		return r;
	}

	public static ResponseUtil ok(String msg) {
		ResponseUtil r = new ResponseUtil();
		r.put("msg", msg);
		return r;
	}
	
	public static ResponseUtil ok(Map<String, Object> map) {
		ResponseUtil r = new ResponseUtil();
		r.putAll(map);
		return r;
	}
	
	public static ResponseUtil ok() {
		return new ResponseUtil();
	}

	public ResponseUtil put(String key, Object value) {
		super.put(key, value);
		return this;
	}
}
